//
//  SKDiscoverCell.m
//  YQFDiscover
//
//  Created by LONG on 16/1/8.
//  Copyright © 2016年 SK. All rights reserved.
//

#import "UIView+SDAutoLayout.h"

#import "SKDiscoverCell.h"

//点赞列表
//#import "SKQuestionZanView.h"

//照片墙
#import "SKWeixinPhotoView.h"



@interface SKDiscoverCell()

@property(nonatomic,strong) UIImageView *iconView;//头像
@property(nonatomic,strong) UILabel *nameView;//昵称
@property(nonatomic,strong) UILabel *textView;//正文
@property(nonatomic,strong) SKWeixinPhotoView *photosView;//照片墙
@property(nonatomic,strong) UILabel *locationView;//位置
@property(nonatomic,strong) UILabel *timeView;//时间
@property(nonatomic,strong) UIButton *commentBtn;//评论按钮
//@property(nonatomic,strong) SKQuestionZanView *zanView;//点赞列表



@end

@implementation SKDiscoverCell


//头像view
- (UIImageView *)iconView
{
    if(_iconView ==nil)
    {
        _iconView =[[UIImageView alloc]init];
        
        [self.contentView addSubview:_iconView];
    }
    
    return _iconView;
}

//昵称
- (UILabel *)nameView
{
    if(_nameView ==nil)
    {
        _nameView =[[UILabel alloc]init];
        //[_nameView setFont:SKNameFont];
        _nameView.numberOfLines = 0;
        
        [self.contentView addSubview:_nameView];
    }
    
    return _nameView;
}


- (UILabel *)textView
{
    if(_textView ==nil)
    {
        _textView =[[UILabel alloc]init];
        _textView.font = [UIFont systemFontOfSize:14];
        _textView.numberOfLines = 0;
        [self.contentView addSubview: _textView];
    }
    
    return _textView;
    
}
- (UILabel *)locationView
{
    if(_locationView ==nil)
    {
        _locationView =[[UILabel alloc]init];
        _locationView.font = [UIFont systemFontOfSize:13];

        _locationView.numberOfLines = 0;
        [self.contentView addSubview: _locationView];
    }
    
    return _locationView;
    
}



//图像view
- (SKWeixinPhotoView *)photosView
{
    if(_photosView ==nil)
    {
        _photosView =[[SKWeixinPhotoView alloc]init];
        
        [self.contentView addSubview:_photosView];
    }
    
    return _photosView;
}

//时间
- (UILabel *)timeView
{
    if(_timeView ==nil)
    {
        _timeView =[[UILabel alloc]init];
        _timeView.font = [UIFont systemFontOfSize:12];

        _timeView.numberOfLines = 0;
        
        [self.contentView addSubview:_timeView];
    }
    
    return _timeView;
}



- (UIButton *)commentBtn
{
    if(_commentBtn==nil)
    {
        
        _commentBtn =[[UIButton alloc]init];
        [_commentBtn setTitle:@"举报" forState:UIControlStateNormal];
        _commentBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_commentBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_commentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
        _commentBtn.adjustsImageWhenHighlighted = NO;
        [self.contentView addSubview:_commentBtn];
    }
    return _commentBtn;
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setData:(SKDiscoverData *)data
{
    _data = data;
    
    UIView *contentView = self.contentView;
    CGFloat margin = 10;
    
    //设置各控件的frame以及data
    
    //头像
    _iconView.sd_layout
    .leftSpaceToView(contentView,margin)
    .topSpaceToView(contentView,margin)
    .heightIs(35)
    .widthIs(35);
    
    //昵称
    _nameView.sd_layout
    .leftSpaceToView(_iconView,margin)
    .topSpaceToView(contentView,1.5 * margin)
    .heightIs(16);
    [_nameView setSingleLineAutoResizeWithMaxWidth:200];
    
   
    
    //文本
    _textView.sd_layout
    .leftEqualToView(_nameView)
    .topSpaceToView(_nameView,margin)
    .rightSpaceToView(contentView,2 * margin)
    .autoHeightRatio(0);
    
    //照片墙
    CGFloat photoMargin = 0;
    if(data.picturesArray.count)
    {
        photoMargin = 10;
    }
    _photosView.sd_layout.leftEqualToView(_nameView);
    _photosView.sd_layout.topSpaceToView(_textView,photoMargin);
    
    //位置
    _locationView.sd_layout.leftEqualToView(_nameView).topSpaceToView(_photosView,margin).heightIs(18);
    [_locationView setSingleLineAutoResizeWithMaxWidth:250];
    
    //时间
    _timeView.sd_layout
    .leftEqualToView(_nameView)
    .topSpaceToView(_locationView,margin)
    .heightIs(18);
    [_timeView setSingleLineAutoResizeWithMaxWidth:250];
    

    //评论按钮
    _commentBtn.sd_layout
    .topEqualToView(_timeView)
    .rightSpaceToView(contentView,2 * margin)
    .widthIs(40)
    .heightIs(25);
    
    //赞列表(必须在赞列表里面处理约束问题，不然会显示不出来)
   // _zanView.sd_layout.leftEqualToView(_nameView);
    CGFloat zanViewTopMargin = 0;
    
    if(data.zanArray.count)
    {
        zanViewTopMargin = 10;
    }
    //_zanView.sd_layout.topSpaceToView(_timeView,zanViewTopMargin);
//
    [self setupAutoHeightWithBottomView:_timeView bottomMargin:margin];

    _iconView.image= [UIImage imageNamed:data.icon];
    _iconView.layer.cornerRadius = _iconView.width * 0.5;
    _iconView.clipsToBounds = YES;
    [_nameView setText:data.name];
    [_timeView setText:data.time];
    [_locationView setText:data.location];
    [_textView setText:data.text];
    _photosView.picPathStringArray = data.picturesArray;
    //_zanView.zanArray = data.zanArray;
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self= [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.userInteractionEnabled = YES;
         self.selectionStyle=UITableViewCellSelectionStyleNone;
        [self iconView];//头像
        [self nameView];//昵称
        [self textView];//正文
        [self photosView];//照片墙
        [self locationView];//位置
        [self timeView];//时间
        [self commentBtn];
        //[self zanView];//点赞列表
        
    }
    return self;
}




@end
